package cn.richard.demo.swagger.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.richard.demo.swagger.StudentService;
import cn.richard.demo.swagger.dto.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags="学生相关接口")
@RestController
@RequestMapping("/student")
public class StudentCtrller {
	@Autowired
	StudentService studentService;
	
	@ApiIgnore
	@ApiOperation("所有学生信息列表")
	@GetMapping
	public Object getAll() {
		return studentService.listAll();
	}
	
	@ApiOperation("通过id查询一个学生信息")
	@GetMapping("/{id}")
	public Object get(@PathVariable Integer id) {
		return studentService.getById(id);
	}
	
	@ApiOperation("通过名称查询一个学生信息")
	@GetMapping("/name")
	//@ApiImplicitParam(name = "name", value = "学生姓名")
	public Object get(@RequestParam String name) {
		return studentService.getByName(name);
	}
	
	@ApiOperation("新增学生信息")
	@PostMapping
	public Object add(Student entity) {
		return studentService.save(entity);
	}
	
	@ApiOperation("修改学生信息")
	@PutMapping
	public Object update(Student entity) {
		return studentService.update(entity);
	}
	
	@ApiOperation("删除学生信息")
	@DeleteMapping("/{id}")
	public Object remove(@PathVariable Integer id) {
		studentService.remove(id);
		return null;
	}
	
}
